package bootstrap

import (
	"blog/app"
	"blog/core"
	router2 "blog/router"
	"github.com/gin-gonic/gin"
	"net/http"
)

type router struct {
	gin *gin.Engine
}

func (rev *router) Init() {
	rev.gin = gin.New()
	port := core.Config.App.Port
	if port == "" {
		port = "8080"
	}
	//加载路由
	rev.loaderRouter()
	rev.loaderMiddleware()
	rev.gin.StaticFS("/go/upload", http.Dir("./upload"))
	rev.gin.Run(":" + port)
}

func (rev *router) loaderMiddleware() {
	rev.gin.Use(app.Middleware.Init()...)
}

func (rev *router) loaderRouter() {
	//TODO::暂时想不到别的方法
	reuters := &router2.Router{}
	reuters.Load(rev.gin)
}
